﻿
using LxCFD;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media.Media3D;

namespace TimeSolve
{
    public class ContinuumVM : BindableBase
    {
        public ContinuumVM(PhysicalModel physicalModel)
        {
            this.physicalModel = physicalModel;
        }
        public PhysicalModel physicalModel;
        public string name { get => physicalModel.name; set { physicalModel.name = value; RaisePropertyChanged("name"); } }
        //public List<MeshVM.ZoneVM> zoneApplied { get => _zonesApplied; set { _zonesApplied = value; } }
        //private List<MeshVM.ZoneVM> _zonesApplied = new List<MeshVM.ZoneVM>();//记录使用该模型的区域
        public PhysicalTypes? physicalType
        {
            get => physicalModel.PhysicalType;
            set
            {
                physicalModel.SetPhysicalType(value);
                RaisePropertyChanged("physicalType");
                materialData = new MaterialDataVM(physicalModel.MaterialData);
            }
        }
        public MaterialDataVM materialData { get => _materialData; set { _materialData = value; RaisePropertyChanged("materialData"); } }
        private MaterialDataVM _materialData;
        public FlowTypes? flowType { get => physicalModel.FlowType; set { physicalModel.FlowType = value; RaisePropertyChanged("flowType"); } }

        public SIMPLEMethods solvingMethod { get => physicalModel.SolvingMethod; set { physicalModel.SolvingMethod = value; RaisePropertyChanged("solvingMethod"); } }

        public ConvectionSchemes convectionScheme { get => physicalModel.ConvectionScheme; set { physicalModel.ConvectionScheme = value; RaisePropertyChanged("convectionScheme"); } }


        public string iniVelocityString
        {
            get
            {
                if (physicalModel.InitialVelocity is Value1Const.Vector vv)
                {
                    return vv.Number.ToString();
                }else
                {
                    return "未定义";
                }
            }
            set
            {
                Vector3d v;
                if (Vector3d.TryParse(out v, value))
                {
                    physicalModel.InitialVelocity = new Value1Const.Vector(v);
                }
                RaisePropertyChanged("iniVelocityString");
            }
        }
        public bool isGravityEnabled { get => physicalModel.IsGravityEnabled; set { physicalModel.IsGravityEnabled = value; RaisePropertyChanged("isGravityEnabled"); } }

        //public Vector3d gravity { get => _gravity; set { _gravity = value; } }
        //private Vector3d _gravity = new Vector3d(0, 0, -9.8);
        public string gravityString
        {
            get => physicalModel.IsGravityEnabled.ToString();
            set
            {
                Vector3d v;
                if (Vector3d.TryParse(out v, value))
                {
                    physicalModel.Gravity = v;
                }
                RaisePropertyChanged("gravityString");
            }
        }
        public bool isEnergyEnabled { get => physicalModel.IsEnergyEnabled; set { physicalModel.IsEnergyEnabled = value; RaisePropertyChanged("isEnergyEnabled"); } }

        public double iniTemperature
        {
            get
            {
                if (physicalModel.InitialTemperature is Value1Const.Double vd)
                {
                    return vd.Number;
                }
                else
                {
                    return 0;
                }
            }
            set
            {
                physicalModel.InitialTemperature = new Value1Const.Double(value);
                RaisePropertyChanged("iniTemperature");
            }
        }


        public RaditionTypes? raditionType { get => physicalModel.RaditionType; set { physicalModel.RaditionType = value; RaisePropertyChanged("raditionType"); } }


        public double MinWallDistance { get => physicalModel.MinWallDistanceLimit; set { physicalModel.MinWallDistanceLimit = value; RaisePropertyChanged("MinWallDistance"); } }

        public bool isBoussinesqEnabled { get => physicalModel.IsBoussinesqEnabled; set { physicalModel.IsBoussinesqEnabled = value; RaisePropertyChanged("isBoussinesqEnabled"); } }

        public double Tref { get => physicalModel.ReferenceTemperature; set { physicalModel.ReferenceTemperature = value; RaisePropertyChanged("Tref"); } }


    }
}

//private void physicalTypeChanged()
//{
//    if (physicalType != null)
//    {
//        MaterialLibrary ml = new MaterialLibrary();
//        materialData = ml.getDefaultMaterial((PhysicalTypes)physicalType);
//    }
//}